package com.xxxx.server.controller;

import com.xxxx.server.pojo.Position;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@Api("职位")
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {

    @Autowired
    private IPositionService positionService;

    @ApiOperation(value = "获取所有职位信息")
    @GetMapping("/")
    public List<Position> queryAll(){
        return positionService.getAll();
    }

    @ApiOperation(value = "添加职位")
    @PostMapping("/")
    public RespBean save(@RequestBody Position position){
        positionService.save(position);
        return RespBean.success("添加成功");
    }

    @ApiOperation(value = "批量删除")
    @DeleteMapping("/")
    public RespBean deleteBatch(Integer[] ids){
        if (!positionService.removeByIds(Arrays.asList(ids))) {
            return RespBean.error("删除失败");
        }
        return RespBean.success("删除成功");
    }

    @ApiOperation(value = "职位名称更新")
    @PutMapping("/")
    public RespBean update(@RequestBody Position position){
        positionService.updateById(position);
        return RespBean.success("更新成功");
    }

    @ApiOperation(value = "单条删除")
    @DeleteMapping("/{id}")
    public RespBean deleteOne(@PathVariable("id") int id){

        positionService.removeById(id);

        return RespBean.success("删除成功");

    }

}
